<template>
  <view class="reading-container" :style="{ paddingTop: navHeight + 'px' }">
    <!-- 顶部搜索栏 -->
    <view class="search-section">
      <view class="search-bar">
        <uni-icons type="search" size="16" color="#909399"></uni-icons>
        <input class="search-input" placeholder="搜索书籍、作者" placeholder-style="color: #909399" />
      </view>
      <image src="/static/navbar/right.svg" class="more-icon" @click="showImportModal = true"></image>
    </view>

 
    <!-- 本地导入书籍区域 -->
    <view class="import-section">
  
      <!-- 导入方式选择 -->
      <view class="import-methods" v-if="showImportModal">
        <view class="modal-backdrop" @click="showImportModal = false"></view>
        <view class="import-modal">
          <view class="modal-header">
            <text class="modal-title">选择导入方式</text>
            <uni-icons type="closeempty" size="20" color="#909399" @click="showImportModal = false"></uni-icons>
          </view>
          
          <view class="import-options">
            <view class="import-option" @click="selectFile">
              <view class="option-icon file">
                <uni-icons type="folder" size="24" color="#2979ff"></uni-icons>
              </view>
              <text class="option-title">文件选择</text>
              <text class="option-desc">从文件夹中选择书籍文件</text>
            </view>
            
            <view class="import-option drag" @dragover.prevent @drop="handleDrop">
              <view class="option-icon drag">
                <uni-icons type="upload" size="24" color="#18bc37"></uni-icons>
              </view>
              <text class="option-title">拖拽上传</text>
              <text class="option-desc">将书籍文件拖拽到此处</text>
            </view>
            
            <view class="import-option scan">
              <view class="option-icon scan">
                <uni-icons type="scan" size="24" color="#f3a73f"></uni-icons>
              </view>
              <text class="option-title">扫描目录</text>
              <text class="option-desc">自动扫描书籍文件夹</text>
            </view>
          </view>
        </view>
      </view>
      

    </view>

  </view>
</template>

<script setup>
import { ref, reactive, computed } from 'vue'
import CustomNavBar from '../../../components/CustomNavBar.vue'

// 响应式数据
const showImportModal = ref(false)
const importingBooks = ref([])

// 导航栏组件引用
const navBarRef = ref(null)
const navHeight = ref(64) // 默认导航栏高度

// 更新导航栏高度的方法
const updateNavHeight = () => {
  try {
    // 确保组件已挂载且存在
    if (navBarRef.value && navBarRef.value.totalNavHeight) {
      // 获取导航栏高度并添加一些额外的间距
      navHeight.value = navBarRef.value.totalNavHeight.value + 10
    }
  } catch (error) {
    console.warn('获取导航栏高度失败，使用默认值:', error)
  }
}

const books = reactive([
  {
    title: '三',
    name: '三体',
    author: '刘慈欣',
    color: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
    progress: 68,
    isNew: false
  },
  {
    title: '活',
    name: '活着',
    author: '余华',
    color: 'linear-gradient(135deg, #f093fb 0%, #f5576c 100%)',
    progress: 100,
    isNew: false
  },
  {
    title: '红',
    name: '红楼梦',
    author: '曹雪芹',
    color: 'linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%)',
    progress: 32,
    isNew: true
  },
  {
    title: '百',
    name: '百年孤独',
    author: '马尔克斯',
    color: 'linear-gradient(135deg, #a8edea 0%, #fed6e3 100%)',
    progress: 15,
    isNew: false
  },
  {
    title: '追',
    name: '追风筝的人',
    author: '卡勒德·胡赛尼',
    color: 'linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%)',
    progress: 85,
    isNew: false
  },
  {
    title: '平',
    name: '平凡的世界',
    author: '路遥',
    color: 'linear-gradient(135deg, #a1c4fd 0%, #c2e9fb 100%)',
    progress: 45,
    isNew: true
  }
])

const recommendations = reactive([
  {
    title: '解',
    name: '解忧杂货店',
    color: 'linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%)'
  },
  {
    title: '白',
    name: '白夜行',
    color: 'linear-gradient(135deg, #a8edea 0%, #fed6e3 100%)'
  },
  {
    title: '人',
    name: '人间失格',
    color: 'linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%)'
  },
  {
    title: '挪威',
    name: '挪威的森林',
    color: 'linear-gradient(135deg, #a1c4fd 0%, #c2e9fb 100%)'
  }
])






</script>

<style lang="scss" scoped>
@import '@/uni.scss';

.reading-container {
  min-height: 100vh;
  background: linear-gradient(180deg, #f8f9fa 0%, #ffffff 100%);
  padding-bottom: 40rpx;
}

// 搜索栏样式
.search-section {
  display: flex;
  align-items: center;
  gap: 20rpx;
  padding: 30rpx 40rpx 20rpx;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  
  .search-bar {
    flex: 1;
    display: flex;
    align-items: center;
    background: #f5f7fa;
    border-radius: 50rpx;
    padding: 20rpx 30rpx;
    box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
    
    .search-input {
      flex: 1;
      margin-left: 15rpx;
      font-size: 28rpx;
      color: $uni-main-color;
      border: none;
      outline: none;
      background: transparent;
    }
  }
  
  .more-icon {
    width: 40rpx;
    height: 40rpx;
    cursor: pointer;
    transition: transform 0.2s ease;
    
    &:active {
      transform: scale(0.9);
    }
  }
}




// 本地导入区域样式
.import-section {
  padding: 40rpx;
  background: #ffffff;
  border-radius: 24rpx;
  margin: 20rpx 40rpx;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
  
  .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30rpx;
    
    .section-title {
      font-size: 32rpx;
      font-weight: 600;
      color: $uni-main-color;
    }
    
    .import-actions {
      .import-btn {
        display: flex;
        align-items: center;
        gap: 10rpx;
        padding: 16rpx 32rpx;
        border-radius: 30rpx;
        font-size: 26rpx;
        font-weight: 500;
        transition: all 0.3s ease;
        cursor: pointer;
        
        &.primary {
          background: $uni-primary;
          color: $uni-white;
          box-shadow: 0 4rpx 16rpx rgba($uni-primary, 0.3);
          
          &:active {
            transform: translateY(-2rpx);
            box-shadow: 0 6rpx 20rpx rgba($uni-primary, 0.4);
          }
        }
      }
    }
  }
  
  // 导入模态框
  .import-methods {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    
    .modal-backdrop {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: rgba(0, 0, 0, 0.5);
      backdrop-filter: blur(4px);
    }
    
    .import-modal {
      position: relative;
      background: $uni-white;
      border-radius: 24rpx;
      padding: 40rpx;
      margin: 40rpx;
      max-width: 600rpx;
      width: 100%;
      box-shadow: 0 20rpx 60rpx rgba(0, 0, 0, 0.3);
      animation: modalSlideIn 0.3s ease;
      
      .modal-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 40rpx;
        
        .modal-title {
          font-size: 32rpx;
          font-weight: 600;
          color: $uni-main-color;
        }
      }
      
      .import-options {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(200rpx, 1fr));
        gap: 30rpx;
        
        .import-option {
          display: flex;
          flex-direction: column;
          align-items: center;
          padding: 40rpx 30rpx;
          border-radius: 20rpx;
          background: #f8f9fa;
          transition: all 0.3s ease;
          cursor: pointer;
          
          &:active {
            transform: translateY(-4rpx);
            box-shadow: 0 8rpx 30rpx rgba(0, 0, 0, 0.15);
          }
          
          .option-icon {
            width: 80rpx;
            height: 80rpx;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: 20rpx;
            
            &.file {
              background: rgba($uni-primary, 0.1);
            }
            
            &.drag {
              background: rgba($uni-success, 0.1);
            }
            
            &.scan {
              background: rgba($uni-warning, 0.1);
            }
          }
          
          .option-title {
            font-size: 28rpx;
            font-weight: 500;
            color: $uni-main-color;
            margin-bottom: 10rpx;
          }
          
          .option-desc {
            font-size: 24rpx;
            color: $uni-secondary-color;
            text-align: center;
          }
        }
      }
    }
  }
  

}


// 动画效果
@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(50rpx) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

// 响应式设计
@media (max-width: 768px) {
  .bookshelf-section .books-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .bookshelf-section .books-grid {
    grid-template-columns: 1fr;
  }
}
</style>